<template>
  <el-table
    :data="newsList"
    style="width: 100%">
    <el-table-column
      prop="id"
      label="编号">
    </el-table-column>
    <el-table-column
      prop="title"
      label="标题">
    </el-table-column>
    <el-table-column
      prop="author"
      label="作者">
    </el-table-column>
    <el-table-column
      label="操作">
      <template slot-scope="scope">
        <el-button @click="deleteNews(scope.row.id)">删除</el-button>
        <el-button>修改</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
    export default {
        name: "newsList",
      data(){
          return {
            newsList:[]
          }
      },
      methods:{
        deleteNews(id){
          this.axios({
            url:"/news/"+id,
            method:"delete"
          }).then((resp)=>{
             this.$message("删除成功！");
          });
        }
      },
      created(){
          this.axios({
            url:"/news",
            method:"get"
          }).then((resp)=>{
            this.newsList=resp.data;
            console.log(this.newsList);
          });
      }
    }
</script>

<style scoped>

</style>
